package com.ethan.minimalist.mvp.presenter

import com.cxz.kotlin.baselibs.ext.startHttp
import com.cxz.kotlin.baselibs.mvp.BasePresenter
import com.ethan.minimalist.mvp.contract.ILoginContract
import com.ethan.minimalist.mvp.model.LoginModel
import com.ethan.minimalist.utils.Md5Utils

/**
 * @author admin
 * @date 2018/11/20
 * @desc
 */
class LoginPresenter : BasePresenter<ILoginContract.Model, ILoginContract.View>(), ILoginContract.Presenter {

    override fun createModel(): ILoginContract.Model? = LoginModel()

    override fun login(username: String, password: String) {
        val pwd = Md5Utils.digest(password)
        mModel?.login(username, pwd)?.startHttp(mModel, mView, onSuccess = {
            mView?.loginSuccess(it.data)
        })
    }

}